package com.topvision.controller.hes;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/sendEmail")
public class SendEmailController {

    @Autowired
    private JavaMailSender mailSender;

    @RequestMapping(method = RequestMethod.GET)
    public String doSendEmail(HttpServletRequest request) {
        // takes input from e-mail form
        String sentFrom = "shengwenming89@163.com";
        String recipientAddress = "179653076@qq.com";
        String message = "测试邮件";

        // prints debug info
        System.out.println("To: " + recipientAddress);
        System.out.println("Message: " + message);

        // creates a simple e-mail object
        SimpleMailMessage email = new SimpleMailMessage();
        email.setFrom(sentFrom);
        email.setTo(recipientAddress);
        email.setText(message);
        email.setSubject("远程协助通知邮件");

        // sends the e-mail
        mailSender.send(email);

        // forwards to the view named "Result"
        return "Result";
    }
}